//
//  DiscountMoreYHHTableViewCell.m
//  AroundTheWorld
//
//  Created by IfelseGo on 16/5/22.
//  Copyright © 2016年 IfelseGo an. All rights reserved.
//

#import "DiscountMoreYHHTableViewCell.h"
#define WIDTH self.frame.size.width
#define HEIGHT self.frame.size.height
#import "DiscountMoreYHHCollectionViewCell.h"
#import "DiscountMoreHot_goodsModel.h"

@implementation DiscountMoreYHHTableViewCell
//自定义初始化
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self addView];
        //        self.smallArray = [NSMutableArray array];
        
    }
    return self;
}

- (void)addView
{
    self.contentView.dk_backgroundColorPicker = DKColorPickerWithRGB(0xffffff,0xCFCFCF);
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    flowLayout.itemSize = CGSizeMake(([UIScreen mainScreen].bounds.size.width - 60) / 2 , 225);
    flowLayout.sectionInset = UIEdgeInsetsMake(20, 20, 20, 20);
    UICollectionView *collectionV = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, 0, 0) collectionViewLayout:flowLayout];
    collectionV.bounces = NO;
    collectionV.showsVerticalScrollIndicator = NO;
    collectionV.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:collectionV];
    
    //成为代理人
    collectionV.delegate = self;
    collectionV.dataSource = self;
    self.myCollectionV = collectionV;
    
    //注册
    UINib *nib = [UINib nibWithNibName:@"DiscountMoreYHHCollectionViewCell" bundle:[NSBundle mainBundle]];
    [self.myCollectionV registerNib:nib forCellWithReuseIdentifier:@"reuse"];
}
//cell数
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 6;
}
//建cell
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    DiscountMoreYHHCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"reuse" forIndexPath:indexPath];
    DiscountMoreHot_goodsModel *model = [self.myGoodsArrayM objectAtIndex:indexPath.row];
    cell.titleLabel.text = model.title;
    cell.priceLabel.text = model.price;
    cell.statusLabel.text = model.status;
    [cell.myImageV sd_setImageWithURL:[NSURL URLWithString:model.photo] placeholderImage:nil];
    return cell;
}


- (void)setMyGoodsArrayM:(NSMutableArray *)myGoodsArrayM
{
    _myGoodsArrayM = myGoodsArrayM;
    [self.myCollectionV reloadData];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    self.myCollectionV.frame = self.contentView.frame;
}

//点击触发方法

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    DiscountMoreHot_goodsModel *model = [self.myGoodsArrayM objectAtIndex:indexPath.row];
    self.myBlock(model.idHot_goods, model.title);
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
